﻿namespace Rialternative.DescriptionProvider
{
    using System;
    using System.Diagnostics.CodeAnalysis;

    /// <summary>
    /// Attribut in charge of an entity type and its exposed methods.
    /// </summary>
    [AttributeUsage(AttributeTargets.Class, AllowMultiple = true)]
    public sealed class EntityDomainAttribute : Attribute
    {
        /// <summary>
        /// Initializes a new instance of the <see cref="EntityDomainAttribute"/> class.
        /// </summary>
        public EntityDomainAttribute()
        {
        }

        /// <summary>
        /// Initializes a new instance of the <see cref="EntityDomainAttribute"/> class.
        /// </summary>
        /// <param name="entityType">Type of the entity.</param>
        /// <param name="operations">The operations.</param>
        public EntityDomainAttribute(Type entityType, EntityDomainOperations operations)
        {
            this.EntityType = entityType;
            this.Operations = operations;
            this.RequiresAuthentication = EntityDomainOperations.None;
            this.QueryRequiresRole = new string[0];
            this.InsertRequiresRole = new string[0];
            this.UpdateRequiresRole = new string[0];
            this.DeleteRequiresRole = new string[0];
        }

        /// <summary>
        /// Gets the type of the entity.
        /// </summary>
        /// <value>The type of the entity.</value>
        public Type EntityType { get; internal set; }

        /// <summary>
        /// Gets the operations.
        /// </summary>
        /// <value>The operations.</value>
        public EntityDomainOperations Operations { get; internal set; }

        /// <summary>
        /// Gets or sets the operations that require authentication
        /// </summary>
        /// <value>The operations that require authentication.</value>
        public EntityDomainOperations RequiresAuthentication { get; set; }

        /// <summary>
        /// Gets or sets the roles that the query operation requires
        /// </summary>
        /// <value>The roles that the query operation requires.</value>
        [SuppressMessage("Microsoft.Performance", "CA1819:PropertiesShouldNotReturnArrays", Justification = "To keep roles definition as simple as possible.")]
        public string[] QueryRequiresRole { get; set; }

        /// <summary>
        /// Gets or sets the roles that the insert operation requires
        /// </summary>
        /// <value>The roles that the insert operation requires.</value>
        [SuppressMessage("Microsoft.Performance", "CA1819:PropertiesShouldNotReturnArrays", Justification = "To keep roles definition as simple as possible.")]
        public string[] InsertRequiresRole { get; set; }

        /// <summary>
        /// Gets or sets the roles that the update operation requires
        /// </summary>
        /// <value>The roles that the update operation requires.</value>
        [SuppressMessage("Microsoft.Performance", "CA1819:PropertiesShouldNotReturnArrays", Justification = "To keep roles definition as simple as possible.")]
        public string[] UpdateRequiresRole { get; set; }

        /// <summary>
        /// Gets or sets the roles that the delete operation requires
        /// </summary>
        /// <value>The roles that the delete operation requires.</value>
        [SuppressMessage("Microsoft.Performance", "CA1819:PropertiesShouldNotReturnArrays", Justification = "To keep roles definition as simple as possible.")]
        public string[] DeleteRequiresRole { get; set; }
    }
}
